//
//  ViewController.m
//  逆向传值(代理)
//
//  Created by whz on 2017/7/10.
//  Copyright © 2017年 王鸿政_whz. All rights reserved.
//

#import "ViewController.h"
#import "ViewController2.h"

@interface ViewController () <ViewControllerDelegate>

@property(nonatomic, strong)UILabel *label1;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self createUI];
}

- (void)createUI {

    self.label1 = [[UILabel alloc] initWithFrame:CGRectMake(self.view.center.x-50, self.view.center.y-25, 100, 50)];
    [self.view addSubview:_label1];
    _label1.text = @"PUSH";
    _label1.textAlignment = NSTextAlignmentCenter;
    _label1.textColor = [UIColor redColor];
    _label1.font = [UIFont systemFontOfSize:20 weight:5];
    _label1.userInteractionEnabled = YES;
    [_label1 addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(push)]];
}

- (void)push {

    ViewController2 *vc2 = [ViewController2 new];
    vc2.str2 = self.label1.text;
    
    vc2.delegate = self;
    
    [self presentViewController:vc2 animated:YES completion:nil];
    
    /*
     传值方法2
     也可以用这种方法传值
     */
//    [self presentViewController:vc2 animated:YES completion:^{
//        vc2.textField2.text = _label1.text;
//    }];
    
}

- (void)pushValue:(NSString *)willPushValue {

    self.label1.text = willPushValue;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
